package edu.univercidade.tcc.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import edu.univercidade.tcc.server.model.Tracker;
import edu.univercidade.tcc.server.service.WorkflowService;

@RooWebScaffold(path = "trackers", formBackingObject = Tracker.class)
@RequestMapping("/trackers")
@Controller
public class TrackerController {

	@Autowired
	private WorkflowService workflowService;

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public String show(@PathVariable("id") Long id, Model uiModel) {
		Tracker tracker = trackerService.findTracker(id);
		uiModel.addAttribute("tracker", tracker);
		uiModel.addAttribute("itemId", id);
		uiModel.addAttribute("isFine",
				workflowService.hasDefaultAndFinalStatus(tracker));
		return "trackers/show";
	}
}
